package com.aurora.storage
{
	public class ArrayMap
	{
		private var _arrKeys:Array;
		private var _arrValues:Array;		
		public function ArrayMap()
		{
			this._arrKeys = new Array();
			this._arrValues = new Array();
		}
        public function add($key:*,$value:*):void{
        	this._arrKeys.push($key);
        	this._arrValues.push($value);
        } 
        public function addAt($key:*,$value:*,$index:int):void{
        	this._arrKeys.splice($index,0,$key);
		this._arrValues.splice($index,0,$value);        	
        }
 
        public function unshift($key:*,$value:*):void{
        	this._arrKeys.unshift($key);
        	this._arrValues.unshift($value);        	
        }
        public function addMap($map:ArrayMap):void{
        	var numLen:int = $map.length;
        	for(var i:int=0; i<numLen; i++){
        		this.add($map.getKeyFromID(i),$map.getValueFromID(i));
        	}
        }
        public function removeWithID($id:int):void{      	
        	this._arrKeys.splice($id,1);
        	this._arrValues.splice($id,1);        	
        }
        public function removeWithKey($key:*):void{  
        	this.removeWithID(this.getIDFromKey($key));   
        }
        public function removeWithValue($value:*):void{
        	this.removeWithID(this.getIDFromValue($value));   
        }
        public function getIDFromKey($key:*):Number{   	
        	var numLen:int = this._arrKeys.length;
        	var numValueID:Number=-1;
        	var first:Boolean=true;
        	for(var i:int=0; i<numLen; i++){
        		if(this._arrKeys[i] == $key && first){
        			first=false;        			
        			numValueID = i;
        		}
        	}
        	if(numValueID==-1){
        		throw new Error("KEY IS NOT CONTAINED IN ARRAY MAP");
        	}
        	return numValueID;
        }
        public function getIDFromValue($value:*):Number{        	
        	var numLen:int = this._arrValues.length;
        	var numValueID:Number=-1;
        	var first:Boolean=true;
        	for(var i:int=0; i<numLen; i++){
        		if(this._arrValues[i] == $value && first){
        			first=false;   
        			numValueID = i;
        		}
        	}
        	if(numValueID==-1){
        		throw new Error("VALUE IS NOT CONTAINED IN ARRAY MAP");
        	}
        	return numValueID;
        }
        public function getValueFromID($id:int):*{
        	return this._arrValues[$id];
        }
        public function getValue($key:*):*{
        	return this.getValueFromID(this.getIDFromKey($key));
        }    
        public function getKeyFromID($id:int):*{
        	return this._arrKeys[$id];
        }
        public function getKey($value:*):*{
        	return this.getValueFromID(this.getIDFromValue($value));
        }        
        public function containsKey($key:*):Boolean{
        	var bolContains:Boolean=false;
        	var numLen:int = this._arrKeys.length;
        	for(var i:int=0; i<numLen; i++){
        		if($key == this._arrKeys[i]){
        			bolContains = true;
        			break;
        		}
        	}
            return bolContains;
        }
        public function containsValue($value:*):Boolean{
        	var bolContains:Boolean=false;
        	var numLen:int = this._arrValues.length;
        	for(var i:int=0; i<numLen; i++){
        		if($value == this._arrValues[i]){
        			bolContains = true;
        			break;
        		}
        	}
            return bolContains;
        }
        /*
        properties
        */   
        public function get values():Array{
        	return this._arrValues;        
        }
        public function get keys():Array{
        	return this._arrKeys;        
        }
        public function get length():int{
        	return this._arrKeys.length;
        }        
        /*
        debugging
        */
        public function debug():void{
        	trace("//////ARRAY MAP DEBUG/////");
        	var numLen:int = this._arrKeys.length;
        	trace("//////Length: "+numLen);
        	for(var i:int=0; i<numLen; i++){
        		trace("ID: "+i+"   KEY: "+this._arrKeys[i]+"   VALUE: "+this._arrValues[i]);
        	}
        }
	}
}